﻿@model Apps.Models.WMS.WMS_Feed_ListModel
@using Apps.Web.Core;
@using Apps.Common;
@using Apps.Models.WMS;
@using Apps.Web;
@using Apps.Locale;
@using Apps.Models.Sys;
@{
    ViewBag.Title = "创建";
    Layout = "~/Views/Shared/_Index_LayoutEdit.cshtml";
    List<permModel> perm = null;
}

<script type="text/javascript">
$(function () {
    $('#Lot').combogrid({
        panelWidth: 300,
        panelHeight: 150,
        sortName: 'Lot',
        idField: 'LotDisp',
        textField: 'LotDisp',
        url: '@Url.Action("GetLotsByPart", "Inv")',
        method: 'post',
        editable: false,
        onSelect: onSelect,        
        columns: [[
            { field: 'Lot', title: '批次号', width: 50, hidden: true },
            {
                field: 'LotDisp', title: '批次号', width: 50
            },
            {field:'Qty',title:'现有量',width:50},
            { field: 'StockQty', title: '备料数', width: 80, sortable: true, align: 'right' },
            { field: 'AvailableQty', title: '可用数量', width: 80, sortable: true, align: 'right' }
        ]],
        fitColumns: true
    });

    $("#btnSave").click(function () {
        if ($("form").valid()) {
            $.ajax({
                url: "@Url.Action("Create")",
                type: "Post",
                data: $("form").serialize(),
                dataType: "json",
                success: function (data) {
                    if (data.type == 1) {
                        window.parent.frameReturnByMes(data.message);
                        window.parent.frameReturnByReload(true);
                        window.parent.frameReturnByClose()
                    }
                    else {
                        window.parent.frameReturnByMes(data.message);
                    }
                }
            });
        }
        return false;
    });
    $("#btnReturn").click(function () {
         window.parent.frameReturnByClose();
    });
});

    function onSelect(index, row)
    {
        $("#Qty").html(row.AvailableQty);
    }

    function LoadLot()
    {
        var invId = $("#InvId").val();
        var subInvId = "";
        var partId = $("#SubAssemblyPartId").val();
        $("#Lot").combogrid('grid').datagrid("load", { partId: partId, invId: invId });
    };

    function frameReturnByClose()
    {
        $("#modalwindow").window('close');
    }

    function frameReturnByMes(mes) {
        $.messageBox5s(Lang.Tip, mes);
    }
</script>
<div id="modalwindow" class="easyui-window" style="width:800px; height:400px;" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>
<div class="mvctool bgb">
    @Html.ToolButton("btnSave", "fa fa-save", Resource.Save, ref perm, "Save", true)
    @Html.ToolButton("btnReturn", "fa fa-reply", Resource.Reply, false)
</div>
@using (Html.BeginForm())
{
    @Html.HiddenFor(model => model.Id, new { @Value = 0 })
    <input id="CreateTime" type="hidden" name="CreateTime" value="2000-1-1" />
    @*@Html.HiddenFor(model => model.FeedBillNum)*@
    <table class="formtable">
        <tbody>
            <tr>
                <th>
                    @Html.LabelFor(model => model.FeedBillNum)：
                </th>
                <td>
                    @*@Model.FeedBillNum*@
                    @Html.EditorFor(model => model.FeedBillNum)（自动生成）
                </td>
                <td>@Html.ValidationMessageFor(model => model.FeedBillNum)</td>
            </tr>
            <tr>
                    <th>
                        @Html.LabelFor(model => model.ReleaseBillNum)：
                    </th>
                    <td>
                        @*@Html.EditorFor(model => model.ReleaseBillNum)*@
                        @Html.ReadOnlyTextBoxFor(model => model.ReleaseBillNum, true)（自动生成）                        
                    </td>
                    <td>@Html.ValidationMessageFor(model => model.ReleaseBillNum)</td>
                </tr>
            <tr>
                <th>
                    @Html.LabelFor(model => model.Department)：
                </th>
                <td>
                    @Html.EditorFor(model => model.Department)
                </td>
                <td>@Html.ValidationMessageFor(model => model.Department)</td>
            </tr>
            <tr>
                <th>
                    @Html.LabelFor(model => model.AssemblyPartId)：
                </th>
                <td>
                    <div style="height:0;width:0;overflow:hidden">
                        @Html.EditorFor(model => model.AssemblyPartId)
                    </div>
                    <input id="AssemblyPartList" name="PartList" readonly="readonly" type="text" style="width: 180px; display: inline; background: #dedede; ">
                    <a class="fa fa-plus-square color-gray fa-lg" href="javascript:showSelPart(false)"></a>
                    <script type="text/javascript">
                        var showSubPart = false;
                        function showSelPart(isSubPart)
                        {
                            showSubPart = isSubPart;
                            $("#modalwindow").html("<iframe width='100%' height='100%' scrolling='no' frameborder='0'' src='/WMS/Part/PartLookUp'></iframe>");
                            $("#modalwindow").window({ title: '选择物料', width: SetGridWidthSub(20), height: SetGridHeightSub(45), iconCls: 'fa fa-plus' }).window('open');
                        }

                        function SetSelResultForPart(result, resultName)
                        {
                            if (showSubPart)
                            {
                                $("#SubAssemblyPartId").val(result);
                                $("#SubAssemblyPartList").val(resultName);
                                LoadLot();
                            }
                            else
                            {
                                $("#AssemblyPartId").val(result);
                                $("#AssemblyPartList").val(resultName);
                                
                            }
                        }
                    </script>
                </td>
                <td>@Html.ValidationMessageFor(model => model.AssemblyPartId)</td>
            </tr>
            <tr>
                <th>
                    @Html.LabelFor(model => model.SubAssemblyPartId)：
                </th>
                <td>
                    <div style="height:0;width:0;overflow:hidden">
                        @Html.EditorFor(model => model.SubAssemblyPartId)
                    </div>
                    <input id="SubAssemblyPartList" name="PartList" readonly="readonly" type="text" style="width: 180px; display: inline; background: #dedede; ">
                    <a class="fa fa-plus-square color-gray fa-lg" href="javascript:showSelPart(true)"></a>
                </td>
                <td>@Html.ValidationMessageFor(model => model.SubAssemblyPartId)</td>
            </tr>
            <tr>
                <th>
                    @Html.LabelFor(model => model.InvId)：
                </th>
                <td>
                    @Html.DropDownListFor(model => model.InvId, ViewBag.Inv as SelectList, new { @onchange = "LoadLot()" })
                </td>
                <td>@Html.ValidationMessageFor(model => model.InvId)</td>
            </tr>
            @*<tr>
                <th>
                    @Html.LabelFor(model => model.SubInvId)：
                </th>
                <td>
                    @Html.EditorFor(model => model.SubInvId)
                </td>
                <td>@Html.ValidationMessageFor(model => model.SubInvId)</td>
            </tr>*@
            <tr>
                <th>
                    批次号：
                </th>
                <td>
                    <input id="Lot" name="Lot" value="">
                    <label id="Qty" for="Lot" name="Qty"></label>
                </td>
                <td>@Html.ValidationMessageFor(model => model.Lot)</td>
            </tr>
            <tr>
                <th>
                    @Html.LabelFor(model => model.FeedQty)：
                </th>
                <td>
                    @Html.EditorFor(model => model.FeedQty)
                </td>
                <td>@Html.ValidationMessageFor(model => model.FeedQty)</td>
            </tr>
            <tr>
                <th>
                    @Html.LabelFor(model => model.BoxQty)：
                </th>
                <td>
                    @Html.EditorFor(model => model.BoxQty)
                </td>
                <td>@Html.ValidationMessageFor(model => model.BoxQty)</td>
            </tr>
            <tr>
                <th>
                    @Html.LabelFor(model => model.Capacity)：
                </th>
                <td>
                    @Html.EditorFor(model => model.Capacity)
                </td>
                <td>@Html.ValidationMessageFor(model => model.Capacity)</td>
            </tr>
            <tr>
                <th>
                    @Html.LabelFor(model => model.Remark)：
                </th>
                <td>
                    @Html.EditorFor(model => model.Remark)
                </td>
                <td>@Html.ValidationMessageFor(model => model.Remark)</td>
            </tr>
        </tbody>
    </table>
}

